package com.wicket.okroperation.common.runner;

import com.wicket.okroperation.common.util.SpringContextUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.Comparator;
import java.util.Map;

@Slf4j
@Component
public class MyApplicationRunner implements ApplicationRunner {

    /**
     * 程序启动后的初始化方法在这里执行
     */
    @Override
    public void run(ApplicationArguments applicationArguments) {
        final Map<String, MyRunner> beans = SpringContextUtil.getBeansOfType(MyRunner.class);
        log.info("system init start");
        beans.values().stream().sorted(Comparator.comparing(MyRunner::order)).forEach(MyRunner::run);
        log.info("system init finish");
    }
}
